/*
 * InstallCellRenderer.java
 *
 * Created on August 4, 2008, 3:48 PM
 */

package jwu2.gui.table;

import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author  jbk
 */
public class DescriptionCellRenderer extends javax.swing.JPanel implements TableCellRenderer {
    private int NORMAL_HEIGHT = 16;
    private int UNFOLDED_HEIGHT = 48;

    /** Creates new form InstallCellRenderer */
    public DescriptionCellRenderer() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        description = new javax.swing.JLabel();

        description.setText("jLabel1");
        description.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        description.setMinimumSize(new java.awt.Dimension(4, 15));
        description.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(description, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(description, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel description;
    // End of variables declaration//GEN-END:variables

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        String text = "";
        if (value!=null) text = (String) value;
        if (isSelected) {
            this.setBackground(table.getSelectionBackground());
            table.setRowHeight(row, this.UNFOLDED_HEIGHT);

        } else {
            this.setBackground(table.getBackground());
            table.setRowHeight(row, this.NORMAL_HEIGHT);
        }
        description.setText(text);
        
        return this;
    }

}
